<style lang="less">
    /*@import '../../../styles/loading.less';*/
</style>
<style scoped>

    .pro-detail-content{
        padding-left: 20px;
        padding-right: 20px;
        margin-bottom: 50px;
    }


    .pro-detail-content .guanli{
        width:20%;
        padding:0;
        border-radius: 0 2px 2px 0;

    }
    .pro-detail-content .btn1{
        display: inline-block;
        height:20px;
        padding: 0 5px;
        margin: 0 5px;
        line-height: 18px;
        border-radius: 3px;
        border:1px solid #C4C4C4;
    }
    
    #submit{
        border-radius:20px;
        width:200px;
    }
    #back{
        border-radius:20px;
        margin-left: 20px;
        width: 120px;
    }
    .pro-detail-content .tagBox{
        border:1px solid #D6D6D6;
        height:36px;
        line-height:36px;
        background-color:#F0F0F0;
        border-radius: 0 2px 2px 0;
    }
    .pro-detail-content .bgk{
        background-color:#EDF2F6 ;
        padding-top: 20px;
        margin-bottom: 20px;
        padding-left: 20px;

    }

    .pro-detail-content .special{
        padding:20px 20px;
        margin-bottom:15px;
    }
    .pro-detail-content .special .ivu-form-item{
        margin-bottom: 15px;
    }
    .pro-detail-content  .special .buttonBox{
        width:100%;
        padding-right:15px;
        margin-bottom:15px;
    }
    .pro-detail-content .special .buttonBox .button{
        border-radius:0;
        width:100%;
    }

    .pro-detail-content .main .ivu-select,.main .ivu-input{
        border-radius: 0 2px 2px 0;
    }
    .common-box-body{
        padding-top: 24px;
    }
    .searchH3{
        border-bottom:1px solid #B3CAD7;
    }
</style>
<style>
    .pro-detail-content .common-box-body .ivu-select-single .ivu-select-selection .ivu-select-placeholder, .common-box-body .ivu-select-single .ivu-select-selection .ivu-select-selected-value{
        padding-right: 0px;
    }

    .pro-detail-content .ivu-tabs.ivu-tabs-card>.ivu-tabs-bar .ivu-tabs-tab{
        color:#2d8cf0;
        border-color:transparent;
        background-color:#FFF;
    }
    .pro-detail-content .ivu-tabs.ivu-tabs-card > .ivu-tabs-bar .ivu-tabs-tab-active{
        color:#808080;
        border: 1px solid #dddee1;
        border-bottom:0;
    }
</style>

<template>
  <div class="pro-detail">
        <product-title></product-title>
        <div class="pro-detail-content ">
             <Form ref="proform" :model="proform" label-position="right"   :rules="ruleValidate" id="main">
                 <div class="common-box-header">
                     <h3>产品基本信息</h3>
                 </div>
                 <div class="common-box-body">
                     <Row>
                         <Col :md="24" :lg="6" >
                         <FormItem label="供应商选择" prop="cid" >
                             <Select v-model="proform.cid"  @on-change="comChange" placeholder="请选择保险公司" filterable>
                                 <template v-for="item in all">
                                     <Option :value="item.cid" :key="item.cid">{{item.name}}</Option>
                                 </template>
                             </Select>
                         </FormItem>
                         </Col>
                         <Col :md="24" :lg="6">
                         <FormItem label="产品名称" prop="pid" >
                             <Select v-model="proform.pid" placeholder="请选择保险产品" @on-change="namechange" label-in-value filterable>
                                 <Option :value="item.id" v-for="(item,index) in three_pro" :key="item.id" :pid="item.id">{{item.name}}</Option>
                             </Select>
                         </FormItem>
                         </Col>
                         <Col :md="24" :lg="6">
                         <FormItem label="产品状态" prop="status" >
                             <Select v-model="proform.status">
                                 <Option value="1">上架</Option>
                                 <Option value="2">下架</Option>
                             </Select>
                         </FormItem>
                         </Col>
                         <Col :md="24" :lg="6">
                         <FormItem label="产品代码" prop="pro_no">
                             <Input v-model="proform.pro_no" placeholder="请输入产品代码"></Input>
                         </FormItem>
                         </Col>
                     </Row>
                     <Row>
                         <Col :md="24" :lg="6">
                         <FormItem label="主附险分类" prop="is_main">
                             <Select v-model="proform.is_main">
                                 <Option value="1">主险</Option>
                                 <Option value="2">附加险</Option>
                                 <Option value="3">组合险</Option>
                             </Select>
                         </FormItem>
                         </Col>
                         <Col :md="24" :lg="6">
                         <FormItem label="承保年龄" >
                             <Input v-model="proform.limit_age" placeholder="填写时 如：0，12"></Input>
                         </FormItem>
                         </Col>
                         <Col :md="24" :lg="6">
                         <FormItem label="计划名称">
                             <Input v-model="proform.plan_name" placeholder="请输入计划名"></Input>
                         </FormItem>
                         </Col>
                         <Col :md="24" :lg="6">
                         <FormItem label="产品分类" >
                             <Select v-model="proform.cate_two" style="width:80%;" @on-change="fenleichange" label-in-value placeholder="请选择产品分类">
                                 <i-option value=" ">不限</i-option>
                                 <template v-for="(item,index) in fenleiArray">
                                     <template v-for="(item1,index1) in item.son">
                                        <i-option :value="item1.id" :key="item1.id" >{{item.cate_name}}-----{{item1.cate_name}}</i-option>
                                     </template>
                                 </template>
                             </Select><Button type="primary" class="guanli" @click="fenModal">
                             管理
                         </Button>
                         </FormItem>
                         </Col>
                     </Row>
                     <Row>
                         <Col :md="24" :lg="12">
                         <FormItem label="交费期间" >
                             <div  class="tagBox">
                                 <template v-for="item in proform.pay_period" v-if="proform.pay_period.length>0">
                                     <span class="btn1">{{item}}</span>
                                 </template>
                             </div>
                         </FormItem>
                         </Col>
                         <Col :md="24" :lg="12">
                         <FormItem label="保险期间" >
                             <div  class="tagBox">
                                 <template v-for="item in proform.period" v-if="proform.period.length>0">
                                     <span class="btn1">{{item}}</span>
                                 </template>
                             </div>
                         </FormItem>
                         </Col>
                     </Row>
                     <Row>
                         <Col :md="24" :lg="24">
                         <FormItem label="必选附加险" >
                             <div  class="tagBox">
                                 <template v-for="(item,index) in proform.additional_must">
                                     <span class="btn1">{{item}}</span>
                                 </template>
                             </div>
                         </FormItem>
                         </Col>
                     </Row>
                     <Row  class="bgk">
                         <Col :md="24" :lg="6" class="col col1">
                         <FormItem label="交费方式">
                             <i-input v-model="pay_typeCont" placeholder="请输入交费方式" style="width:80%;border-radius:0px !important;"></i-input><Button type="success" class="guanli" @click="pay_typeAdd">添加</Button>
                         </FormItem>
                         </Col>
                         <Col :md="24" :lg="18" class="col">
                         <Tag v-for="item in proform.pay_type" :key="item" :name="item" closable type="dot" color="blue" @on-close="pay_typeRemove">{{item}}</Tag>
                         </Col>
                     </Row>
                 </div>
                <div class="common-box-header" style="">
                    <h3>
                        APP相关信息
                    </h3>
                </div>
                 <div class="common-box-body">
                     <Row>
                         <Col :md="24" :lg="6">
                         <FormItem label="热门" prop="is_hot" >
                             <Select v-model="proform.is_hot"  placeholder="请选择">
                                 <Option value="0" >否</Option>
                                 <Option value="1" >是</Option>
                             </Select>
                         </FormItem>
                         </Col>
                         <Col :md="24" :lg="6">
                         <FormItem label="电投" prop="is_net" >
                             <Select v-model="proform.is_net"  placeholder="请选择">
                                 <Option value="0" >否</Option>
                                 <Option value="1" >是</Option>
                             </Select>
                         </FormItem>
                         </Col>
                         <Col :md="24" :lg="6">
                         <FormItem label="推荐" prop="is_rec" >
                             <Select v-model="proform.is_rec"  placeholder="请选择">
                                 <Option value="0" >否</Option>
                                 <Option value="1" >是</Option>
                             </Select>
                         </FormItem>
                         </Col>
                         <Col :md="24" :lg="6">
                         <FormItem label="最新" prop="is_new" >
                             <Select v-model="proform.is_new"  placeholder="请选择">
                                 <Option value="0" >否</Option>
                                 <Option value="1" >是</Option>
                             </Select>
                         </FormItem>
                         </Col>

                     </Row>
                     <!-- <FormItem label="排序" prop="px">
                         <Row>
                             <Col :md="24 ":lg="8">
                             <Input v-model="proform.px" placeholder="请输入"></Input>
                             </Col>
                         </Row>
                     </FormItem> -->
                     <Row class="bgk" style="margin-bottom:15px;">
                         <Col :md="24" :lg="6" class="col col1">
                         <FormItem label="标签" >
                             <i-input v-model="labelCont" placeholder="请输入标签" style="width:80%;border-radius:0px !important;"></i-input><Button type="success" class="guanli" @click="labeladd">添加</Button>
                         </FormItem>
                         </Col>
                         <Col :md="24" :lg="18" class="col">
                         <Tag v-for="item in proform.label" :key="item" :name="item" closable type="dot" color="blue" @on-close="labelremove">{{item}}</Tag>
                         </Col>
                     </Row>
                     <Row class="bgk special">
                         <Col :md="24" :lg="6">
                         <FormItem label="特色标题" >
                             <i-input v-model="specialTitle" placeholder="请输入特色标题"></i-input>
                         </FormItem>
                         <FormItem label="特色内容">
                             <i-input v-model="specialCont" placeholder="请输入特色内容"></i-input>
                         </FormItem>
                         <div class="buttonBox">
                             <Button type="success" class="button" @click="specialAdd">
                                 <Icon type="plus"></Icon>
                                 添加特色
                             </Button>
                         </div>
                         </Col>
                         <Col :md="24" :lg="18">
                         <Tag v-for="(item,index) in proform.special" :key="item.key" :name="item.key" closable type="dot" color="blue" @on-close="specialRemove(index)">{{item.key}} | {{item.val}} </Tag>
                         </Col>
                     </Row>
                     <Row class="bgk special">
                         <Col :md="24" :lg="6" >
                         <FormItem label="条件标题" >
                             <i-input v-model="conditionTitle" placeholder="请输入条件标题"></i-input>
                         </FormItem>
                         <FormItem label="条件内容">
                             <i-input v-model="conditionCont" placeholder="请输入条件内容"></i-input>
                         </FormItem>
                         <div  class="buttonBox">
                             <Button class="button" type="success" @click="conditionAdd">
                                 <Icon type="plus"></Icon>
                                 添加条件
                             </Button>
                         </div>
                         </Col>
                         <Col :md="24" :lg="18">
                         <Tag v-for="(item,index) in proform.condition" :key="item.key" :name="item.key" closable type="dot" color="blue" @on-close="conditionRemove(index)">{{item.key}}：{{item.val}} </Tag>
                         </Col>
                     </Row>
                     <Row class="bgk">
                         <Col :md="24" :lg="24" v-if="tuijianTitle">
                         <div style="height:42px;line-height:42px;border:1px solid #F3D6A9;background-color:#FFE1BF;padding:0 15px;margin:0 5px 8px 5px;color:#F16F47;">
                             提示：请先添加 <span v-html="tuijianTitle"></span>保险，然后在进行更多推荐附加险操作 &emsp;<a href="http://biz.kuaibao365.com/#/pro/create" target="_Blank">去添加>></a></p>
                         </div>
                         </Col>
                         <Col :md="24" :lg="6" >
                         <FormItem label="推荐附加险" prop="additional" >
                             <Select @on-change="additionalChange($event)" label-in-value filterable style="width:80%;" v-model="additional_id" disabled>
                                 <template v-for="(item1,index1) in proform.recommend_nothave">
                                     <Option :value="item1.id" :key="item1.id">{{item1.name}}</Option>
                                 </template>
                             </Select><Button type="success" class="guanli" @click="add_additional" disabled>
                             添加
                         </Button>
                         </FormItem>
                         </Col>
                         <Col :md="24" :lg="18">
                         <Tag v-for="(item,index) in proform.additional_recommend" :key="item.id" :name="item.id" type="dot" color="blue" v-if="item.id?true:false" closable @on-close="remove_additional(index)">{{item.name}}</Tag>
                         </Col>
                     </Row>
                 </div>
                 <div class="common-box-header mb15"  >
                     <h3>
                         条款资料信息
                     </h3>
                 </div>
                 <div>

                 </div>
                <Row class="bgk" style="margin-bottom:15px;">
                    <Col :md="24" :lg="3" class="pdfBox">
                            <input type="file" id="pdfFile" style="display:none;" @change="pdfFile1($event)">
                            <Button type="success" class="guanli" style="width:100%;" @click="pdfFile">
                                <Icon type="plus" ></Icon>
                                上传条款PDF
                            </Button>
                    </Col>
                    <Col :md="24" :lg="21" class="bgd" style="height:60px;">
                            <Tag  type="dot" color="blue" v-if="proform.pdf_name" style="margin-left: 10px;" closable @on-close="handleClose2">{{proform.pdf_name}}</Tag>
                    </Col>
                </Row>
                <Row>
                    <Col :md="24" :lg="24">
                        <Tabs type="card" :animated="false">
                            <TabPane label="保险责任">
                                <UE :defaultMsg="proform.rights"  ref="rights" id="rights" v-model="proform.rights"></UE>
                            </TabPane>
                            <TabPane label="投保该规则">
                                <UE :defaultMsg="proform.rule"  ref="rule" id="rule"></UE>
                            </TabPane>
                            <TabPane label="责任免除">
                                <UE :defaultMsg="proform.exclusion"  ref="exclusion" id="exclusion"></UE>
                            </TabPane>
                            <TabPane label="案例说明">
                                <UE :defaultMsg="proform.cases"  ref="cases" id="cases"></UE>
                            </TabPane>
                            <TabPane label="详细条款">
                                <UE :defaultMsg="proform.clause"  ref="clause" id="clause"></UE>
                            </TabPane>
                            <TabPane label="病种详情">
                                <UE :defaultMsg="proform.illness"  ref="illness" id="illness"></UE>
                            </TabPane>
                        </Tabs>
                    </Col>
                </Row>
            </Form>
            <div id="footer" class="pt22">
            <Button type="primary" shape="circle" id="submit" @click="handleSubmit('proform')" style="border-radius: 30px !important;">
                <Icon type="checkmark-circled"></Icon>
                保存 / 提交
            </Button>
            <Button id="back" shape="circle" @click="back" style="border-radius: 30px !important;">返回</Button>
            </div>
        </div>
      
      <Modal
        v-model="modal1"
        title="分类管理"
        width="900px"
        class="fenlei"
        :mask-closable="false"
        >
        <Row style="height:400px;">
        <i-col :md="14" :lg="14" class="pr15" style="padding:16px;height:100%;overflow:scroll;overflow-x:hidden;">
                    <div>
                        <template v-for="(item,index) in fenleiArray">
                            <div class="zhu">
                                <span class=""  class="pointer" @click="true1(index)">
                                    <Icon type="chevron-up" class="ml15 mr10" v-if="xianshi==index"></Icon>
                                    <Icon type="chevron-down" class="ml15 mr10 pointer" v-else></Icon>
                                </span>
                                <input type="text" v-if="bianji==index" v-model="bianjiCont" class="outLine">
                                <span v-else class="" style="color:#4D7FE4;">{{item.cate_name}}</span>
                                <span class="fr caozuo create" @click="bianji1(index,item.id)"  v-if="bianji==index" style="background-color:#18BF6D;">
                                    <Icon type="checkmark-round"></Icon>
                                </span>
                                <span class="fr caozuo create" @click="bianji1(index,item.id)" v-else >
                                    <Icon type="android-create"></Icon>
                                </span>
                                <span class="fr caozuo del" @click="delete1(item.id)">
                                    <Icon type="trash-a"></Icon>
                                </span>
                            </div>
                            <div class="fu" v-if="xianshi==index">
                                <template v-for="(item1,index1) in item.son">
                                    <div class="list">
                                        <Icon class="ml15"></Icon>
                                        ---------&nbsp;&nbsp;
                                        <!-- <input type="text"> -->
                                        <input type="text" v-if="bianjiTwo == index1" v-model="bianjiCont1">
                                        <span v-else>{{item1.cate_name}}</span>
                                        <span class="fr caozuo create" @click="bianji2(index,index1,item1.id)"  v-if="bianjiTwo==index1" style="background-color:#18BF6D;">
                                            <Icon type="checkmark-round"></Icon>
                                        </span>
                                        <span class="fr caozuo create" @click="bianji2(index,index1,item1.id)" v-else >
                                            <Icon type="android-create"></Icon>
                                        </span>
                                        <span class="fr caozuo del" @click="delete1(item1.id)">
                                            <Icon type="trash-a"></Icon>
                                        </span>
                                    </div>
                                </template>
                            </div>
                        </template>
                        
                    </div>
                </i-col>
                <i-col :md="10" :lg="10" style="padding:15px;background-color:#CEEAF7;height:100%;">
                    <h3 class="searchH3 mt16" x>添加分类</h3>
                    <Form ref="fenleiForm" :model="fenleiForm" label-position="left" :label-width="80" id="fenleiForm">
                        <i-col :md="24" :lg="24">
                            <FormItem label="上级分类" prop="cate_first" class="bian">
                                <i-select placeholder="请选择上级分类" v-model="fenleiForm.cate_id">
                                    <i-option value="0">根分类</i-option>
                                    <template v-for="(item,index) in cateFirst">
                                        <i-option :value="item.id">{{item.cate_name}}</i-option>
                                    </template>
                                </i-select>
                            </FormItem>
                        </i-col>
                        <i-col :md="24" :lg="24">
                            <FormItem label="分类名称" prop="cate_two" class="bian">
                                <Input type="text"  placeholder="请输入分类名称" v-model="fenleiForm.cate_name">
                                </Input>
                            </FormItem>
                        </i-col>
                        <i-col :md="24" :lg="24" class="tCenter">
                            <i-button type="primary" shape="circle" @click="cate_create">
                                <Icon class="iconfont icon-dui" style="font-size:14px;"></Icon>&emsp;
                                新增分类</i-button>
                        </i-col>
                    </Form>
                </i-col>
        </Row>
        
        
    </Modal>
  </div>
</template>
<script>
import productTitle from '../../components/productTitle';

//旧
//import { getComlist} from '../../api/parter';
//import { create , get_third_pro_list , getThirdProDetail ,get_all ,update ,get_third_pro_detail
//,get_detail } from '../../api/product_v2';
//import { get_cate_first ,get_cate_second ,getCompany1,_all_company , } from '../../api/parter';
//

//新
import { _get_parter_list, _pro_third_list ,_pro_third_info,_create,_cate_first,_cate_list,_cate_delete,_cate_create,_cate_update,_cate_info} from '../../api/product_v2'
import {getStsTokenWrite,getStsTokenRead} from '../../api/common'

import UE from '../UE/ue.vue';
import '../../../static/UEdit/ueditor.config.js';
import '../../../static/UEdit/ueditor.all.js';
import '../../../static/UEdit/lang/zh-cn/zh-cn.js';
import '../../../static/UEdit/ueditor.parse.js';
export default {
    data () {
        return {
            fenleiArray:[],
            xianshi:-1,
            bianji:-1,
            bianjiTwo:-1,
            bianjiCont:'',
            bianjiCont1:'',
            fenleiForm:{
                cate_id:'',
                cate_name:'',
            },
            cateFirst:[],
            zhedie:'1',
            modal1:false,
            //推荐附加险提示
            tuijianTitle:'',



            // tag 内容暂存位置
                //交费方式
                pay_typeCont:'',
                //标签
                labelCont:'',
                //特色
                specialTitle:'',
                specialCont:'',
                //条件
                conditionTitle:'',
                conditionCont:'',
                //推荐附加险
                additional_id:'',
                additional_name:'',
            proform:{
                pdf_url:'',
                pdf_name:'',
                px:'0',
                id:'0',
                cid:'',//所属公司id
                name:'',
                pid:'',
                pro_no:'',
                additional_must:[],
                plan_name:'',
                cate_one:'',
                cate_two:'',
                is_main:'1',
                limit_age:'',
                insurance_period:[],
                pay_period:[],
                period:[],
                pay_type:[],
                condition:[],
                status:'1',
                label:[],
                special:[
                ],
                additional:[],
                is_new:'0',
                is_rec:'0',
                is_net:'0',
                is_hot:'0',
                // 缺少必选附加险
                must_nothave:[],

                 //保险责任
                    rights:'',
                    //投保规则
                    rule:'',
                    //案例说明
                    cases:'',
                    //详细条款
                    clause:'',
                    //病重详情
                    illness:'',
                    //责任免除
                exclusion:'',
                recommend_nothave:[],//没有的可推荐的附加

                additional_recommend:[],//推荐附加险
            },
            all:[],//所有公司
            three_pro:[],//第三方
            ruleValidate:{
                 pid: [
                     { required: true, message: '不能为空'}
                 ],
                 cid: [
                     { required: true, message: '不能为空' }
                 ],
//                 pro_no: [
//                     { required: true, message: '不能为空' }
//                 ],
                 status:[
                     { required: true, message: '不能为空' }
                 ],
             }
        };
    },
    components: {
        productTitle,
        UE
    },
    created () {
        this.getall();
        this.cate_first();
        this.cate_list();
    },
    activated(){

    },
    methods: {
        pdfFile1(e){
                var file = e.target.files[0];
                if (!/\.(pdf|doc|docx)$/.test(e.target.value)) {
                    alert('文件类型必须是pdf,word中的一种')
                    return false
                }
                const pdf = document.getElementById('pdfFile');
                let files=pdf.files[0];
                getStsTokenWrite().then((res)=>{
                    if(res.data.err==0){
                        var sts = res.data.data.Credentials;
                        var client = new OSS.Wrapper({
                            region:'oss-cn-hangzhou',
                            accessKeyId: sts.AccessKeyId,
                            accessKeySecret: sts.AccessKeySecret,
                            stsToken: sts.SecurityToken,
                            bucket: 'kuaibao-imgs',
                            secure: true,
                        });
                        console.log(client);
                        client.multipartUpload(files.name, files, {

                        }).then((results) => {
                            if(file.size>100){
                                this.proform.pdf_url = '';
                                this.proform.pdf_name = '';

                                this.proform.pdf_url = results.res.requestUrls[0].split('?')[0];
                                this.proform.pdf_name = files.name;
                            }else if(results.url){
                                this.proform.pdf_url = '';
                                this.proform.pdf_name = '';
                                this.proform.pdf_name = files.name;
                                this.proform.pdf_url = results.url;
                            }else{
                                alert('上传失败！');
                                return false;
                            }
                        })
                    }
                })
        },
        pdfFile(){
                let pdf=document.getElementById('pdfFile');
                pdf.click();
        },
        //富文本内容获取
        getUEContent() {
                this.proform.clause = this.$refs.clause.getUEContent();
                this.proform.rule = this.$refs.rule.getUEContent();
                this.proform.illness = this.$refs.illness.getUEContent();
                this.proform.cases = this.$refs.cases.getUEContent();
                this.proform.exclusion = this.$refs.exclusion.getUEContent();
                this.proform.rights = this.$refs.rights.getUEContent();
        },
        additionalChange(value){
                this.additional_id=value.value;
                this.additional_name=value.label;
        },
//        推荐附加险
        add_additional(){
            let can=false;
            new Promise((rev,rej)=>{
                this.proform.additional_recommend.map(item=>{
                    if(item.id == this.additional_id){
                        can=true;
                        alert('已经添加');
                        this.additional_id='';
                        this.additional_name='';
                        return false;
                    }
                })
                rev();
            }).then(()=>{
                if(!can){
                    this.proform.additional_recommend.push({
                        id:this.additional_id,
                        name:this.additional_name
                    });
                    this.additional_id='';
                    this.additional_name='';
                }
            })
        },
        remove_additional(index){
            this.proform.additional_recommend.splice(index,1);
        },
//        获取所有公司
        getall(){
            new Promise((resolve,reject)=>{
                _get_parter_list().then(res=>{
                    if(res.data.err==0){
                        this.all=[];
                        this.all = res.data.data;
                    }else{
                        this.$Message.error('供应商'+res.data.info);
                    }
                    resolve();
                }).catch(error=>{
                    reject(error);
                })

            })
        },
        //保险公司切换
        comChange(value){
            let _params = {
                cid:value
            }
            this.proform.cid = value;
            new Promise((resolve, reject) => {
                _pro_third_list(_params).then(response => {
                    if(response.data.err == 0){
                        this.three_pro = response.data.data;
                    } else {
                        this.$Message.error('产品名称'+response.data.info);
                    }
                    resolve();
                }).catch(error => {
                    reject(error);
                });
            });
        },
        //产品切换
        namechange(value){
            this.proform.name = value.label;
            let params ={
                pid :value.value
            }
            new Promise((resolve,reject)=>{
                _pro_third_info(params).then(res=>{
                    if(res.data.err==0){

//                        this.proform.pid = value.value;

                        this.proform.is_main = res.data.data.is_main?res.data.data.is_main.toString():'1';
                        this.proform.status = res.data.data.status?res.data.data.status.toString():'1';

                        this.proform.pay_period = res.data.data.pay_period;
                        //保险期间
                        this.proform.period = res.data.data.insurance_period;
                        //热门  最新  电投   推荐
                        this.proform.is_new = res.data.data.is_new?res.data.data.is_new.toString():'0';
                        this.proform.is_rec = res.data.data.is_rec?res.data.data.is_rec.toString():'0';
                        this.proform.is_hot = res.data.data.is_hot?res.data.data.is_hot.toString():'0';
                        this.proform.is_net = res.data.data.is_net?res.data.data.is_net.toString():'0';


                        if(res.data.data.recommend_nothave.length>0){
                            let queshi = '';
                            res.data.data.recommend_nothave.map(item=>{
//                                queshi+=item.name+',';
                                queshi+=`<a href="http://biz.kuaibao365.com/#/pro/update/`+item.id+`" target="_Blank">`+item.name+ `</a>`+',';
                            })
                            this.tuijianTitle = queshi;
                        }
                        this.proform.recommend_nothave = res.data.data.recommend_nothave;
                        this.proform.additional_recommend = res.data.data.recommend_have;

                        this.proform.pdf_name = res.data.data.pdf_name;
                        this.proform.pdf_url = res.data.data.pdf_url;



                        this.proform.rights = res.data.data.rights?res.data.data.rights:'';
                        this.$refs.rights.setUEContent(this.proform.rights);

                        this.proform.rule = res.data.data.rule?res.data.data.rule:'';
                        this.$refs.rule.setUEContent(this.proform.rule);

                        this.proform.exclusion = res.data.data.exclusion?res.data.data.exclusion:'';
                        this.$refs.exclusion.setUEContent(this.proform.exclusion);
//
                        this.proform.cases = res.data.data.cases?res.data.data.cases:'';
                        this.$refs.cases.setUEContent(this.proform.cases);

                        this.proform.clause = res.data.data.clause?res.data.data.clause:'';
                        this.$refs.clause.setUEContent(this.proform.clause);

                        this.proform.illness = res.data.data.illness?res.data.data.illness:'';
                        this.$refs.illness.setUEContent(this.proform.illness);

                        if(res.data.data.limit_age){
                            let limit_age = res.data.data.limit_age.split(',');
                            this.proform.limit_age = limit_age[0]+'-'+limit_age[limit_age.length-1]+'周岁';
                        }
                        //必选附加险
                        this.proform.additional_must=res.data.data.must_have;
//                        this.proform.additional_must=[1,2,3,5,6];
                        if(res.data.data.must_nothave.length>0){
                            let queshi = '';
                            res.data.data.must_nothave.map(item=>{
                                queshi+=item.name+'，';
                            })
                            this.$Modal.confirm({
                                title:'必选附加险缺失',
                                content:queshi+'缺失,请先添加！！！<br><p><a href="http://biz.kuaibao365.com/#/pro/create" target="_Blank">去添加>></a></p>',
                                onOk:()=>{
                                }
                            })
                        }
                    }else{
                        this.$Message.error(res.data.info);
                    }
                    resolve();
                }).catch(error=>{
                    reject(error);
                })
            })
        },

        //一级分类change
        first_class_change(){
            let first_class_id={
                id:this.proform.cate_one
            }
            new Promise((resolve,reject)=>{
                get_cate_second(first_class_id).then(res=>{
                    if(res.data.err==0){
                        this.cate_two_list = res.data.data;
                    }else{
                        this.$Message.error(res.data.info);
                    }
                    resolve();
                }).catch(error=>{
                    reject(error);
                })
            })
        },
        //条件
        conditionAdd() {
                if(this.conditionTitle.length>0&&this.conditionCont.length>0){
                    this.proform.condition.push({
                        key:this.conditionTitle,
                        val:this.conditionCont
                    })
                    this.conditionTitle='';
                    this.conditionCont='';
                }

        },
        conditionRemove(index) {
                this.proform.condition.splice(index, 1);
        },

        //特色
        specialAdd(){
            if(this.specialTitle.length>0){
                this.proform.special.push({
                    key:this.specialTitle,
                    val:this.specialCont
                });
            }
            this.specialTitle="";
            this.specialCont="";
        },
        specialRemove(index) {
            this.proform.special.splice(index, 1);
        },

        //交费方式
        pay_typeAdd () {
            if(this.pay_typeCont.length>0){
                    this.proform.pay_type.push(this.pay_typeCont);
                    this.pay_typeCont='';
            }
        },
        pay_typeRemove(event, name) {
                const index = this.proform.pay_type.indexOf(name);
                this.proform.pay_type.splice(index, 1);
            },
        // 标签
        labeladd() {
                if (this.labelCont.length > 0) {
                    this.proform.label.push(this.labelCont);
                    this.labelCont = '';
                } else {
                    this.labelCont = '';

                }
        },
        labelremove(event, name) {
                const index = this.proform.label.indexOf(name);
                this.proform.label.splice(index, 1);
        },
        sendAll( name ) {
            new Promise((resolve,rejecct)=>{
                _create(this.proform).then(res=>{
                    if(res.data.err==0){
                        this.$router.push({name:'pro'});
                    }else{
                        this.$Message.error(res.data.info);
                    }
                    resolve();
                }).catch(error=>{
                    rejecct(error);
                });
            });
        },
        handleSubmit (name) {
            this.getUEContent();
            this.$refs[name].validate((valid) => {
                if (valid) {
                   this.sendAll();
                } else {
                    this.$Message.error('参数出错!');
                }
            })
        },
        back(){
            this.$router.push({name:'pro'})
        },
        fenModal(){
            this.modal1 = true;
        },
        true1(val){
            if(this.xianshi == val){
                this.xianshi=-1;
                this.bianji = -1;
                this.bianjiTwo = -1;
                this.bianjiCont1="";
                this.bianjiCont="";

            }else{
                this.xianshi = val;
            }
        },
        delete1(id){
            let params={
                cate_id:id
            }
            new Promise((resolve,rejecct)=>{
                _cate_delete(params).then(res=>{
                    if(res.data.err==0){
                        this.cate_list();
                        this.cate_first();
                        this.$Message.success('操作成功！');
                    }else{
                        this.$Message.error(res.data.info);
                    }
                    resolve();
                }).catch(error=>{
                    rejecct(error);
                });
            });
        },
        bianji1(val,id){
            if(this.bianji == val){
                this.bianji=-1;
                this.cate_update(id,this.bianjiCont);
                let _this = this;
                setTimeout(function(){
                        _this.cate_list();   
                        _this.bianjiCont = "";
                    _this.$Message.success('操作成功！');
                },1000)

                // this.$set('fenleiArray',this.fenleiArray);
            }else{
                this.bianji = val;
                this.bianjiCont = this.fenleiArray[val].cate_name;
                // console.log(this.ceshi[val].zhu.name)
            }
        },
        bianji2(val,val1,id){
            if(this.bianjiTwo==val1){
                this.bianjiTwo=-1;
                this.cate_update(id,this.bianjiCont1);
                let _this = this;
                setTimeout(function(){
                        _this.cate_list();   
                        _this.bianjiCont1 = "";
                        _this.$Message.success('操作成功！');
                },1000)
            }else{
                this.bianjiCont1 = this.fenleiArray[val].son[val1].cate_name;
                this.bianjiTwo=val1;
            }
        },
        //获取分类
        cate_list(){
            new Promise((resolve,rejecct)=>{
                _cate_list().then(res=>{
                    if(res.data.err==0){
                        this.fenleiArray = res.data.data.list;
                    }else{
                        this.$Message.error(res.data.info);
                    }
                    resolve();
                }).catch(error=>{
                    rejecct(error);
                });
            });
        },
        //一级分类
        cate_first(){
            new Promise((resolve,rejecct)=>{
                _cate_first().then(res=>{
                    if(res.data.err==0){
                        this.cateFirst = res.data.data;
                    }else{
                        this.$Message.error(res.data.info);
                    }
                    resolve();
                }).catch(error=>{
                    rejecct(error);
                });
            });
        },
        //新增分类
        cate_create(){
            new Promise((resolve,rejecct)=>{
                _cate_create(this.fenleiForm).then(res=>{
                    if(res.data.err==0){
                        this.$Message.success('操作成功');
                        this.cate_list();
                        this.cate_first();
                        this.fenleiForm.cate_id = "";
                        this.fenleiForm.cate_name = "";
                    }else{
                        this.$Message.error(res.data.info);
                    }
                    resolve();
                }).catch(error=>{
                    rejecct(error);
                });
            });
        },
        //修改分类
        cate_update(id,name){
            let params={
                cate_id:id,
                cate_name:name
            }
            new Promise((resolve,rejecct)=>{
                _cate_update(params).then(res=>{
                    if(res.data.err==0){
                        console.log(res.data.date);
                    }else{
                        this.$Message.error(res.data.info);
                    }
                    resolve();
                }).catch(error=>{
                    rejecct(error);
                });
            });
        },
        fenleichange(val){
            this.proform.cate_two=val.value;
            let params= {
                cate_id:val.value
            }
            new Promise((resolve,rejecct)=>{
                _cate_info(params).then(res=>{
                    if(res.data.err==0){
                        this.proform.cate_one = res.data.data[0].pid;
                    }else{
                        this.$Message.error(res.data.info);
                    }
                    resolve();
                }).catch(error=>{
                        rejecct(error);
                });
            });
        },
        handleClose2(){
            this.proform.pdf_url="";
            this.proform.pdf_name="";
        }

    },
    mounted(){
        
    }
}
</script>

